package text.java;

import org.apache.log4j.Logger;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import pojo.Supplier;
import service.SupplierService;

import java.util.ArrayList;
import java.util.List;

public class SupplierTest {
    private Logger logger = Logger.getLogger(SupplierTest.class);
    @Test
    public void supplierTest(){
        ApplicationContext context = new ClassPathXmlApplicationContext("appLicationTest.xml");
        SupplierService service =  context.getBean(SupplierService.class);
        List<Supplier> list = new ArrayList<Supplier>();
        Supplier supplier = new Supplier();
        supplier.setSupName("北");
        list = service.getlist(supplier);
        for (Supplier supplier1:list){
            logger.debug(supplier1.toString());
        }
    }
    @Test
    public void addTest(){
        ApplicationContext context = new ClassPathXmlApplicationContext("appLicationTest.xml");
        SupplierService service = context.getBean(SupplierService.class);
        Supplier supplier = new Supplier();
        supplier.setSupCode("BJ_GY020");
        supplier.setSupName("北京xxx");
        supplier.setSupDesc("xxxx");
        supplier.setSupContact("李四");
        supplier.setSupPhone("12345678912");
        supplier.setSupAddress("xxx区");
        supplier.setSupFax("010-123456");
        supplier.setCreatedTime("2021-03-21");
        supplier.setCreatedUserId("2");
        supplier.setUpdatedTime("2021-5-5");
        supplier.setUpdatedUserId("1");
        boolean result = service.add(supplier);
        logger.debug("result:"+result);
    }
    @Test
    public void deleteTest(){
        ApplicationContext context = new ClassPathXmlApplicationContext("appLicationTest.xml");
        SupplierService service = context.getBean(SupplierService.class);
        Supplier supplier = new Supplier();
        supplier.setId(18);
        boolean result = service.delete(supplier);
        logger.debug("result:"+result);
    }
    @Test
    public void updateTest(){
        ApplicationContext context = new ClassPathXmlApplicationContext("appLicationTest.xml");
        SupplierService service = context.getBean(SupplierService.class);
        Supplier supplier = new Supplier();
        supplier.setSupName("雷晴");
        supplier.setId(16);
        boolean result = service.update(supplier);
        logger.debug("result:"+result);
    }
}